<!DOCTYPE HTML>
<html lang="zh-tw" >
    <!-- Start book Flask框架 -->
    <head>
        <!-- head:start -->
        <meta charset="UTF-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <title>数据库的设置 | Flask框架</title>
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <meta name="description" content="">
        <meta name="generator" content="GitBook 2.6.7">
        
        
        <meta name="HandheldFriendly" content="true"/>
        <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
        <meta name="apple-mobile-web-app-capable" content="yes">
        <meta name="apple-mobile-web-app-status-bar-style" content="black">
        <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../gitbook/images/apple-touch-icon-precomposed-152.png">
        <link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">
        
    <link rel="stylesheet" href="../gitbook/style.css">
    
        
        <link rel="stylesheet" href="../gitbook/plugins/gitbook-plugin-toggle-chapters/toggle.css">
        
    
        
        <link rel="stylesheet" href="../gitbook/plugins/gitbook-plugin-splitter/splitter.css">
        
    
        
        <link rel="stylesheet" href="../gitbook/plugins/gitbook-plugin-emphasize/plugin.css">
        
    
        
        <link rel="stylesheet" href="../gitbook/plugins/gitbook-plugin-highlight/website.css">
        
    
        
        <link rel="stylesheet" href="../gitbook/plugins/gitbook-plugin-fontsettings/website.css">
        
    
    

        
    
    
    <link rel="next" href="../c04/s02.html" />
    
    
    <link rel="prev" href="../c04/index.html" />
    

        <!-- head:end -->
    </head>
    <body>
        <!-- body:start -->
        
    <div class="book"
        data-level="4.1"
        data-chapter-title="数据库的设置"
        data-filepath="c04/s01.md"
        data-basepath=".."
        data-revision="Sat Oct 28 2017 17:13:14 GMT+0800 (中国标准时间)"
        data-innerlanguage="">
    

<div class="book-summary">
    <nav role="navigation">
        <ul class="summary">
            
            
            
            

            

            
    
        <li class="chapter " data-level="0" data-path="index.html">
            
                
                    <a href="../index.html">
                
                        <i class="fa fa-check"></i>
                        
                        引言
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1" data-path="c01/index.html">
            
                
                    <a href="../c01/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.</b>
                        
                        关于Flask
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.1" data-path="c01/s01.html">
            
                
                    <a href="../c01/s01.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.1.</b>
                        
                        了解框架
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="c01/s02.html">
            
                
                    <a href="../c01/s02.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.2.</b>
                        
                        安装环境
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="2" data-path="c02/index.html">
            
                
                    <a href="../c02/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.</b>
                        
                        视图
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.1" data-path="c02/s01.html">
            
                
                    <a href="../c02/s01.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.1.</b>
                        
                        从Hello World开始
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.2" data-path="c02/s02.html">
            
                
                    <a href="../c02/s02.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.2.</b>
                        
                        扩展
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="3" data-path="c03/index.html">
            
                
                    <a href="../c03/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.</b>
                        
                        模板
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="3.1" data-path="c03/s01.html">
            
                
                    <a href="../c03/s01.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.1.</b>
                        
                        变量
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.2" data-path="c03/s02.html">
            
                
                    <a href="../c03/s02.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.2.</b>
                        
                        过滤器
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.3" data-path="c03/s03.html">
            
                
                    <a href="../c03/s03.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.3.</b>
                        
                        web表单
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.4" data-path="c03/s04.html">
            
                
                    <a href="../c03/s04.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.4.</b>
                        
                        控制语句
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.5" data-path="c03/s05.html">
            
                
                    <a href="../c03/s05.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.5.</b>
                        
                        宏、继承、包含
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.6" data-path="c03/s06.html">
            
                
                    <a href="../c03/s06.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.6.</b>
                        
                        Flask的特殊变量和方法
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="4" data-path="c04/index.html">
            
                
                    <a href="../c04/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.</b>
                        
                        数据库
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter active" data-level="4.1" data-path="c04/s01.html">
            
                
                    <a href="../c04/s01.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.1.</b>
                        
                        数据库的设置
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.2" data-path="c04/s02.html">
            
                
                    <a href="../c04/s02.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.2.</b>
                        
                        数据库的基本操作
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.3" data-path="c04/s03.html">
            
                
                    <a href="../c04/s03.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.3.</b>
                        
                        自定义模型类
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.4" data-path="c04/s04.html">
            
                
                    <a href="../c04/s04.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.4.</b>
                        
                        数据库迁移
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.5" data-path="c04/s05.html">
            
                
                    <a href="../c04/s05.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.5.</b>
                        
                        邮件扩展
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="5" data-path="c05/index.html">
            
                
                    <a href="../c05/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.</b>
                        
                        测试与部署
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="5.1" data-path="c05/s01.html">
            
                
                    <a href="../c05/s01.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.1.</b>
                        
                        蓝图
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.2" data-path="c05/s02.html">
            
                
                    <a href="../c05/s02.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.2.</b>
                        
                        单元测试
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.3" data-path="c05/s03.html">
            
                
                    <a href="../c05/s03.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.3.</b>
                        
                        部署
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.4" data-path="c05/s04.html">
            
                
                    <a href="../c05/s04.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.4.</b>
                        
                        RESTful
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.5" data-path="c05/s05.html">
            
                
                    <a href="../c05/s05.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.5.</b>
                        
                        性能
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    


            
            <li class="divider"></li>
            <li>
                <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
                    本書使用 GitBook 釋出
                </a>
            </li>
            
        </ul>
    </nav>
</div>

    <div class="book-body">
        <div class="body-inner">
            <div class="book-header" role="navigation">
    <!-- Actions Left -->
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href="../" >Flask框架</a>
    </h1>
</div>

            <div class="page-wrapper" tabindex="-1" role="main">
                <div class="page-inner">
                
                
                    <section class="normal" id="section-">
                    
                        <h1 id="41-&#x6570;&#x636E;&#x5E93;&#x7684;&#x8BBE;&#x7F6E;">4.1 &#x6570;&#x636E;&#x5E93;&#x7684;&#x8BBE;&#x7F6E;</h1>
<p>Web&#x5E94;&#x7528;&#x4E2D;&#x666E;&#x904D;&#x4F7F;&#x7528;&#x7684;&#x662F;&#x5173;&#x7CFB;&#x6A21;&#x578B;&#x7684;&#x6570;&#x636E;&#x5E93;&#xFF0C;&#x5173;&#x7CFB;&#x578B;&#x6570;&#x636E;&#x5E93;&#x628A;&#x6240;&#x6709;&#x7684;&#x6570;&#x636E;&#x90FD;&#x5B58;&#x50A8;&#x5728;&#x8868;&#x4E2D;&#xFF0C;&#x8868;&#x7528;&#x6765;&#x7ED9;&#x5E94;&#x7528;&#x7684;&#x5B9E;&#x4F53;&#x5EFA;&#x6A21;&#xFF0C;&#x8868;&#x7684;&#x5217;&#x6570;&#x662F;&#x56FA;&#x5B9A;&#x7684;&#xFF0C;&#x884C;&#x6570;&#x662F;&#x53EF;&#x53D8;&#x7684;&#x3002;&#x5B83;&#x4F7F;&#x7528;&#x7ED3;&#x6784;&#x5316;&#x7684;&#x67E5;&#x8BE2;&#x8BED;&#x8A00;&#x3002;&#x5173;&#x7CFB;&#x578B;&#x6570;&#x636E;&#x5E93;&#x7684;&#x5217;&#x5B9A;&#x4E49;&#x4E86;&#x8868;&#x4E2D;&#x8868;&#x793A;&#x7684;&#x5B9E;&#x4F53;&#x7684;&#x6570;&#x636E;&#x5C5E;&#x6027;&#x3002;&#x6BD4;&#x5982;&#xFF1A;&#x5546;&#x54C1;&#x8868;&#x91CC;&#x6709;name&#x3001;price&#x3001;number&#x7B49;&#x3002;
Flask&#x672C;&#x8EAB;&#x4E0D;&#x9650;&#x5B9A;&#x6570;&#x636E;&#x5E93;&#x7684;&#x9009;&#x62E9;&#xFF0C;&#x4F60;&#x53EF;&#x4EE5;&#x9009;&#x62E9;SQL&#x6216;NOSQL&#x7684;&#x4EFB;&#x4F55;&#x4E00;&#x79CD;&#x3002;&#x4E5F;&#x53EF;&#x4EE5;&#x9009;&#x62E9;&#x66F4;&#x65B9;&#x4FBF;&#x7684;SQLALchemy&#xFF0C;&#x7C7B;&#x4F3C;&#x4E8E;Django&#x7684;ORM&#x3002;SQLALchemy&#x5B9E;&#x9645;&#x4E0A;&#x662F;&#x5BF9;&#x6570;&#x636E;&#x5E93;&#x7684;&#x62BD;&#x8C61;&#xFF0C;&#x8BA9;&#x5F00;&#x53D1;&#x8005;&#x4E0D;&#x7528;&#x76F4;&#x63A5;&#x548C;SQL&#x8BED;&#x53E5;&#x6253;&#x4EA4;&#x9053;&#xFF0C;&#x800C;&#x662F;&#x901A;&#x8FC7;Python&#x5BF9;&#x8C61;&#x6765;&#x64CD;&#x4F5C;&#x6570;&#x636E;&#x5E93;&#xFF0C;&#x5728;&#x820D;&#x5F03;&#x4E00;&#x4E9B;&#x6027;&#x80FD;&#x5F00;&#x9500;&#x7684;&#x540C;&#x65F6;&#xFF0C;&#x6362;&#x6765;&#x7684;&#x662F;&#x5F00;&#x53D1;&#x6548;&#x7387;&#x7684;&#x8F83;&#x5927;&#x63D0;&#x5347;&#x3002;</p>
<p>SQLAlchemy&#x662F;&#x4E00;&#x4E2A;&#x5173;&#x7CFB;&#x578B;&#x6570;&#x636E;&#x5E93;&#x6846;&#x67B6;&#xFF0C;&#x5B83;&#x63D0;&#x4F9B;&#x4E86;&#x9AD8;&#x5C42;&#x7684;ORM&#x548C;&#x5E95;&#x5C42;&#x7684;&#x539F;&#x751F;&#x6570;&#x636E;&#x5E93;&#x7684;&#x64CD;&#x4F5C;&#x3002;flask-sqlalchemy&#x662F;&#x4E00;&#x4E2A;&#x7B80;&#x5316;&#x4E86;SQLAlchemy&#x64CD;&#x4F5C;&#x7684;flask&#x6269;&#x5C55;&#x3002;</p>
<h3 id="&#x6570;&#x636E;&#x5E93;&#x5B89;&#x88C5;">&#x6570;&#x636E;&#x5E93;&#x5B89;&#x88C5;</h3>
<p><strong> &#x5B89;&#x88C5;&#x670D;&#x52A1;&#x7AEF;</strong></p>
<pre><code>sudo apt-get install mysql-server
</code></pre><p><strong> &#x5B89;&#x88C5;&#x5BA2;&#x6237;&#x7AEF;</strong></p>
<pre><code>sudo apt-get install mysql-client
</code></pre><pre><code>sudo apt-get install libmysqlclient-dev
</code></pre><h4 id="&#x6570;&#x636E;&#x5E93;&#x7684;&#x57FA;&#x672C;&#x547D;&#x4EE4;">&#x6570;&#x636E;&#x5E93;&#x7684;&#x57FA;&#x672C;&#x547D;&#x4EE4;</h4>
<p><strong> &#x767B;&#x5F55;&#x6570;&#x636E;&#x5E93;</strong></p>
<pre><code>mysql -u root -p
</code></pre><p><strong> &#x521B;&#x5EFA;&#x6570;&#x636E;&#x5E93;&#xFF0C;&#x5E76;&#x8BBE;&#x5B9A;&#x7F16;&#x7801;</strong></p>
<pre><code>create database &lt;&#x6570;&#x636E;&#x5E93;&#x540D;&gt; charset=utf8;
</code></pre><p><strong> &#x663E;&#x793A;&#x6240;&#x6709;&#x6570;&#x636E;&#x5E93;</strong></p>
<pre><code>show databases;
</code></pre><h3 id="&#x5728;flask&#x4E2D;&#x4F7F;&#x7528;mysql&#x6570;&#x636E;&#x5E93;&#xFF0C;&#x9700;&#x8981;&#x5B89;&#x88C5;&#x4E00;&#x4E2A;flasksqlalchemy&#x7684;&#x6269;&#x5C55;&#x3002;">&#x5728;Flask&#x4E2D;&#x4F7F;&#x7528;mysql&#x6570;&#x636E;&#x5E93;&#xFF0C;&#x9700;&#x8981;&#x5B89;&#x88C5;&#x4E00;&#x4E2A;flask-sqlalchemy&#x7684;&#x6269;&#x5C55;&#x3002;</h3>
<pre><code>pip install flask-sqlalchemy
</code></pre><p>&#x8981;&#x8FDE;&#x63A5;mysql&#x6570;&#x636E;&#x5E93;&#xFF0C;&#x4ECD;&#x9700;&#x8981;&#x5B89;&#x88C5;flask-mysqldb</p>
<pre><code>pip install flask-mysqldb
</code></pre><h3 id="&#x4F7F;&#x7528;flasksqlalchemy&#x7BA1;&#x7406;&#x6570;&#x636E;&#x5E93;">&#x4F7F;&#x7528;Flask-SQLAlchemy&#x7BA1;&#x7406;&#x6570;&#x636E;&#x5E93;</h3>
<p>&#x4F7F;&#x7528;Flask-SQLAlchemy&#x6269;&#x5C55;&#x64CD;&#x4F5C;&#x6570;&#x636E;&#x5E93;&#xFF0C;&#x9996;&#x5148;&#x9700;&#x8981;&#x5EFA;&#x7ACB;&#x6570;&#x636E;&#x5E93;&#x8FDE;&#x63A5;&#x3002;&#x6570;&#x636E;&#x5E93;&#x8FDE;&#x63A5;&#x901A;&#x8FC7;URL&#x6307;&#x5B9A;&#xFF0C;&#x800C;&#x4E14;&#x7A0B;&#x5E8F;&#x4F7F;&#x7528;&#x7684;&#x6570;&#x636E;&#x5E93;&#x5FC5;&#x987B;&#x4FDD;&#x5B58;&#x5230;Flask&#x914D;&#x7F6E;&#x5BF9;&#x8C61;&#x7684;SQLALCHEMY_DATABASE_URI&#x952E;&#x4E2D;&#x3002;</p>
<p><strong> &#x5BF9;&#x6BD4;&#x4E0B;Django&#x548C;Flask&#x4E2D;&#x7684;&#x6570;&#x636E;&#x5E93;&#x8BBE;&#x7F6E;&#xFF1A;</strong></p>
<p><span class="pg-emphasize pg-emphasize-yellow" style="background: #fff100;">Django&#x7684;&#x6570;&#x636E;&#x5E93;&#x8BBE;&#x7F6E;&#xFF1A;</span>
 <img src="../images/Django&#x4E2D;&#x8BBE;&#x7F6E;&#x6570;&#x636E;&#x5E93;.png" alt="Django&#x4E2D;&#x8BBE;&#x7F6E;&#x6570;&#x636E;&#x5E93;"></p>
<p><span class="pg-emphasize pg-emphasize-yellow" style="background: #fff100;">Flask&#x7684;&#x6570;&#x636E;&#x5E93;&#x8BBE;&#x7F6E;&#xFF1A;</span> </p>
<p>app.config[&apos;SQLALCHEMY_DATABASE_URI&apos;] = &apos;mysql://root:mysql@127.0.0.1:3306/test3&apos;</p>
<h3 id="&#x5E38;&#x7528;&#x7684;sqlalchemy&#x5B57;&#x6BB5;&#x7C7B;&#x578B;">&#x5E38;&#x7528;&#x7684;SQLAlchemy&#x5B57;&#x6BB5;&#x7C7B;&#x578B;</h3>
<table>
<thead>
<tr>
<th>&#x7C7B;&#x578B;&#x540D;</th>
<th>python&#x4E2D;&#x7C7B;&#x578B;</th>
<th>&#x8BF4;&#x660E;</th>
</tr>
</thead>
<tbody>
<tr>
<td>Integer</td>
<td>int</td>
<td>&#x666E;&#x901A;&#x6574;&#x6570;&#xFF0C;&#x4E00;&#x822C;&#x662F;32&#x4F4D;</td>
</tr>
<tr>
<td>SmallInteger</td>
<td>int</td>
<td>&#x53D6;&#x503C;&#x8303;&#x56F4;&#x5C0F;&#x7684;&#x6574;&#x6570;&#xFF0C;&#x4E00;&#x822C;&#x662F;16&#x4F4D;</td>
</tr>
<tr>
<td>BigInteger</td>
<td>int&#x6216;long</td>
<td>&#x4E0D;&#x9650;&#x5236;&#x7CBE;&#x5EA6;&#x7684;&#x6574;&#x6570;</td>
</tr>
<tr>
<td>Float</td>
<td>float</td>
<td>&#x6D6E;&#x70B9;&#x6570;</td>
</tr>
<tr>
<td>Numeric</td>
<td>decimal.Decimal</td>
<td>&#x666E;&#x901A;&#x6574;&#x6570;&#xFF0C;&#x4E00;&#x822C;&#x662F;32&#x4F4D;</td>
</tr>
<tr>
<td>String</td>
<td>str</td>
<td>&#x53D8;&#x957F;&#x5B57;&#x7B26;&#x4E32;</td>
</tr>
<tr>
<td>Text</td>
<td>str</td>
<td>&#x53D8;&#x957F;&#x5B57;&#x7B26;&#x4E32;&#xFF0C;&#x5BF9;&#x8F83;&#x957F;&#x6216;&#x4E0D;&#x9650;&#x957F;&#x5EA6;&#x7684;&#x5B57;&#x7B26;&#x4E32;&#x505A;&#x4E86;&#x4F18;&#x5316;</td>
</tr>
<tr>
<td>Unicode</td>
<td>unicode</td>
<td>&#x53D8;&#x957F;Unicode&#x5B57;&#x7B26;&#x4E32;</td>
</tr>
<tr>
<td>UnicodeText</td>
<td>unicode</td>
<td>&#x53D8;&#x957F;Unicode&#x5B57;&#x7B26;&#x4E32;&#xFF0C;&#x5BF9;&#x8F83;&#x957F;&#x6216;&#x4E0D;&#x9650;&#x957F;&#x5EA6;&#x7684;&#x5B57;&#x7B26;&#x4E32;&#x505A;&#x4E86;&#x4F18;&#x5316;</td>
</tr>
<tr>
<td>Boolean</td>
<td>bool</td>
<td>&#x5E03;&#x5C14;&#x503C;</td>
</tr>
<tr>
<td>Date</td>
<td>datetime.date</td>
<td>&#x65F6;&#x95F4;</td>
</tr>
<tr>
<td>Time</td>
<td>datetime.datetime</td>
<td>&#x65E5;&#x671F;&#x548C;&#x65F6;&#x95F4;</td>
</tr>
<tr>
<td>LargeBinary</td>
<td>str</td>
<td>&#x4E8C;&#x8FDB;&#x5236;&#x6587;&#x4EF6;</td>
</tr>
</tbody>
</table>
<h3 id="&#x5E38;&#x7528;&#x7684;sqlalchemy&#x5217;&#x9009;&#x9879;">&#x5E38;&#x7528;&#x7684;SQLAlchemy&#x5217;&#x9009;&#x9879;</h3>
<table>
<thead>
<tr>
<th>&#x9009;&#x9879;&#x540D;</th>
<th>&#x8BF4;&#x660E;</th>
</tr>
</thead>
<tbody>
<tr>
<td>primary_key</td>
<td>&#x5982;&#x679C;&#x4E3A;True&#xFF0C;&#x4EE3;&#x8868;&#x8868;&#x7684;&#x4E3B;&#x952E;</td>
</tr>
<tr>
<td>unique</td>
<td>&#x5982;&#x679C;&#x4E3A;True&#xFF0C;&#x4EE3;&#x8868;&#x8FD9;&#x5217;&#x4E0D;&#x5141;&#x8BB8;&#x51FA;&#x73B0;&#x91CD;&#x590D;&#x7684;&#x503C;</td>
</tr>
<tr>
<td>index</td>
<td>&#x5982;&#x679C;&#x4E3A;True&#xFF0C;&#x4E3A;&#x8FD9;&#x5217;&#x521B;&#x5EFA;&#x7D22;&#x5F15;&#xFF0C;&#x63D0;&#x9AD8;&#x67E5;&#x8BE2;&#x6548;&#x7387;</td>
</tr>
<tr>
<td>nullable</td>
<td>&#x5982;&#x679C;&#x4E3A;True&#xFF0C;&#x5141;&#x8BB8;&#x6709;&#x7A7A;&#x503C;&#xFF0C;&#x5982;&#x679C;&#x4E3A;False&#xFF0C;&#x4E0D;&#x5141;&#x8BB8;&#x6709;&#x7A7A;&#x503C;</td>
</tr>
<tr>
<td>default</td>
<td>&#x4E3A;&#x8FD9;&#x5217;&#x5B9A;&#x4E49;&#x9ED8;&#x8BA4;&#x503C;</td>
</tr>
</tbody>
</table>
<h3 id="&#x5E38;&#x7528;&#x7684;sqlalchemy&#x5173;&#x7CFB;&#x9009;&#x9879;">&#x5E38;&#x7528;&#x7684;SQLAlchemy&#x5173;&#x7CFB;&#x9009;&#x9879;</h3>
<table>
<thead>
<tr>
<th>&#x9009;&#x9879;&#x540D;</th>
<th>&#x8BF4;&#x660E;</th>
</tr>
</thead>
<tbody>
<tr>
<td>backref</td>
<td>&#x5728;&#x5173;&#x7CFB;&#x7684;&#x53E6;&#x4E00;&#x6A21;&#x578B;&#x4E2D;&#x6DFB;&#x52A0;&#x53CD;&#x5411;&#x5F15;&#x7528;</td>
</tr>
<tr>
<td>primary join</td>
<td>&#x660E;&#x786E;&#x6307;&#x5B9A;&#x4E24;&#x4E2A;&#x6A21;&#x578B;&#x4E4B;&#x95F4;&#x4F7F;&#x7528;&#x7684;&#x8054;&#x7ED3;&#x6761;&#x4EF6;</td>
</tr>
<tr>
<td>uselist</td>
<td>&#x5982;&#x679C;&#x4E3A;False&#xFF0C;&#x4E0D;&#x4F7F;&#x7528;&#x5217;&#x8868;&#xFF0C;&#x800C;&#x4F7F;&#x7528;&#x6807;&#x91CF;&#x503C;</td>
</tr>
<tr>
<td>order_by</td>
<td>&#x6307;&#x5B9A;&#x5173;&#x7CFB;&#x4E2D;&#x8BB0;&#x5F55;&#x7684;&#x6392;&#x5E8F;&#x65B9;&#x5F0F;</td>
</tr>
<tr>
<td>secondary</td>
<td>&#x6307;&#x5B9A;&#x591A;&#x5BF9;&#x591A;&#x4E2D;&#x8BB0;&#x5F55;&#x7684;&#x6392;&#x5E8F;&#x65B9;&#x5F0F;</td>
</tr>
<tr>
<td>secondary join</td>
<td>&#x5728;SQLAlchemy&#x4E2D;&#x65E0;&#x6CD5;&#x81EA;&#x884C;&#x51B3;&#x5B9A;&#x65F6;&#xFF0C;&#x6307;&#x5B9A;&#x591A;&#x5BF9;&#x591A;&#x5173;&#x7CFB;&#x4E2D;&#x7684;&#x4E8C;&#x7EA7;&#x8054;&#x7ED3;&#x6761;&#x4EF6;</td>
</tr>
</tbody>
</table>

                    
                    </section>
                
                
                </div>
            </div>
        </div>

        
        <a href="../c04/index.html" class="navigation navigation-prev " aria-label="Previous page: 数据库"><i class="fa fa-angle-left"></i></a>
        
        
        <a href="../c04/s02.html" class="navigation navigation-next " aria-label="Next page: 数据库的基本操作"><i class="fa fa-angle-right"></i></a>
        
    </div>
</div>

        
<script src="../gitbook/app.js"></script>

    
    <script src="../gitbook/plugins/gitbook-plugin-toggle-chapters/toggle.js"></script>
    

    
    <script src="../gitbook/plugins/gitbook-plugin-splitter/splitter.js"></script>
    

    
    <script src="../gitbook/plugins/gitbook-plugin-sharing/buttons.js"></script>
    

    
    <script src="../gitbook/plugins/gitbook-plugin-fontsettings/buttons.js"></script>
    

    
    <script src="../gitbook/plugins/gitbook-plugin-livereload/plugin.js"></script>
    

<script>
require(["gitbook"], function(gitbook) {
    var config = {"toggle-chapters":{},"splitter":{},"emphasize":{},"highlight":{},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2},"livereload":{}};
    gitbook.start(config);
});
</script>

        <!-- body:end -->
    </body>
    <!-- End of book Flask框架 -->
</html>
